<template>
  <div>
    <div class="select_top">
      <el-date-picker
        style="width:15%;margin-right:1%"
        v-model="year"
        type="year"
        placeholder="选择年"
        :clearable="false"
        valueFormat="yyyy"
      >
      </el-date-picker>
      <el-button @click="gettestList">筛选</el-button>
    </div>
    <el-table
      ref="filterTable"
      :data="testList"
      v-loading="loadingt"
      style="width: 92%;font-size:13px;margin: 20px auto;"
    >
      <el-table-column
        type="index"
        label="序号"
      >
      </el-table-column>
      <el-table-column
        prop="hash.aorgname"
        label="考核部门"
      >
      </el-table-column>
      <el-table-column
        prop="hash.time"
        label="填报时间"
      >
      </el-table-column>
      <el-table-column
        prop="hash.statusname"
        label="状态"
      >
      </el-table-column>
      <el-table-column
        label="操作"
        width="120"
      >
        <template slot-scope="scope">
          <div v-if="belongunit!='3'">
            <el-button
              v-if="scope.row.hash.statusname=='已完成'"
              @click="edit(scope.row)"
              type="primary"
              size="small"
            >
              查看
            </el-button>
            <el-button
              @click="edit(scope.row)"
              v-else-if="scope.row.hash.statusname=='草稿'"
              type="primary"
              size="small"
            >
              编辑
            </el-button>
            <el-button
              @click="edit(scope.row)"
              v-else
              type="primary"
              size="small"
            >
              填报
            </el-button>
          </div>
          <div v-else>
            <el-button
              v-if="scope.row.hash.statusname=='已完成'"
              @click="edit(scope.row)"
              type="primary"
              size="small"
            >
              查看
            </el-button>
            <el-button
              v-else
              size="small"
              @click="cannotsee"
            >
              查看
            </el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog
      title=""
      :visible.sync="showCheck"
      width="90%"
    >
      <el-table
        :data="detailList"
        border
      >
        <el-table-column
          type="index"
          width="50"
          label="序号"
        >
        </el-table-column>
        <el-table-column
          label="考核指标"
        >
          <template slot-scope="scope">
            各职能单位履职
          </template>
        </el-table-column>
        <el-table-column
          prop="hash.borgname"
          label="评议对象"
        >
        </el-table-column>
        <el-table-column
          label="评议内容"
        >
          <el-table-column
            :renderHeader="foo1"
          >
            <el-table-column labelClassName="f10"
              label="未按要求参加城市管理办事处组织开展的专项整治行动的，每次扣0.1。示例：如扣0.1分则填写0.1"
            >
              <template slot-scope="scope">
                — <el-input v-model="scope.row.hash.score1" type="number" min="0"
                  v-validate="'required'" name="协调配合"
                  style="width:80%"
                ></el-input>
                <div style="font-size:11px;color:#e78a42">{{ errors.first('协调配合') }}</div>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column
            :renderHeader="foo2"
          >
            <el-table-column labelClassName="f10"
              label="对城市管理办事处反馈的民生诉求，未按时落实情况的落实不到位的，每次扣0.1-0.2分。示例：如扣0.1分则填写0.1"
            >
              <template slot-scope="scope">
                — <el-input v-model="scope.row.hash.score2"
                  v-validate="'required'" name="工作成效"
                  style="width:80%" type="number"
                ></el-input>
                <div style="font-size:11px;color:#e78a42">{{ errors.first('工作成效') }}</div>
              </template>
            </el-table-column>
          </el-table-column>
        </el-table-column>
        <el-table-column
          label="问题及建议"
        >
          <template slot-scope="scope">
            <el-input v-model="scope.row.hash.remark" clearable></el-input>
          </template>
        </el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer" v-if="ishowsubmit">
        <el-button @click="saveEdit">暂 存</el-button>
        <el-button type="primary" @click="sumitEdit">提 交</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import tooltip from '~/components/common/tooltip.vue';

export default {
  data() {
    return {
      belongunit: localStorage.getItem('belongunit'),
      showCheck: false,
      ts: this.newStore(),
      loadingt: true,
      year: '',
      ishowsubmit: false,
      testList: [],
      detailList: [],
    };
  },
  components: {
    tooltip,
  },
  created() {
    this.year = `${new Date().getFullYear()}`;
    this.gettestList();
  },
  methods: {
    // isout1(val) {
    //   for (let i = 0; i < this.detailList.length; i += 1) {
    //     if (val > 0.1) {
    //       this.$message({
    //         message: '协调配合分数不能大于0.1',
    //         type: 'error',
    //       });
    //       return;
    //     }
    //   }
    // },
    // isout2(val) {
    //   for (let i = 0; i < this.detailList.length; i += 1) {
    //     if (val > 0.1) {
    //       this.$message({
    //         message: '工作成效分数不能大于0.2',
    //         type: 'error',
    //       });
    //       return;
    //     }
    //   }
    // },
    cannotsee() {
      this.$message({
        message: '该状态下不可查看！',
        type: 'info',
      });
    },
    foo1() {
      return (
          <el-tooltip
          popper-class="tip1"
          effect="dark"
          content="1.办事处牵头组织开展各项专项整治行动时，相关部门未按要求派员参加的，每次扣0.1分;
          2. 办事处发函提请相关市级业务部门协调有关工作，相关部门未按要求派员予以履职指导、反馈意见的，每次扣0.05分;
          3.相关部门派员参与专项整治行动时，不服从指挥，存在不
作为、乱作为、慢作为情形的，每次扣0.1分"
          placement="bottom"
          >
            <span>协调配合<i class="el-icon-question"></i></span>
          </el-tooltip>
      );
    },
    foo2() {
      return (
          <el-tooltip
          popper-class="tip1"
          effect="dark"
          content="1.相关部门未在规定时间完成、反馈市委、市政府批示督办
件或办事处函告抄告职能工作事项的，每次扣0.1分;
2.
相关部门整改不到位，造成重复投诉或苏州市级以上信访
平台投诉的，每次扣0.1 分;
3.相关部门拒不按协调会商要求落实，推诿扯皮，未在规定
时间内落实整改的，每次扣0.2分
"
          placement="bottom"
          >
            <span>工作成效<i class="el-icon-question"></i></span>
          </el-tooltip>
      );
    },
    sumitEdit() {
      this.$validator.validateAll().then((result) => {
        if (result) {
          for (let i = 0; i < this.detailList.length; i += 1) {
            if (Number(this.detailList[i].hash.score1) < 0 || Number(this.detailList[i].hash.score2) < 0) {
              this.$message({
                message: '请检查，得分不能小于0',
                type: 'error',
              });
              return false;
            }
          }
          const f = [];
          for (let i = 0; i < this.detailList.length; i += 1) {
            const req = {
              handle: '04A3682CDCA57EBA0DA6C15FB2ECC84B571521205BF7630E125D30625A61C18F',
              score1: this.detailList[i].hash.score1,
              score2: this.detailList[i].hash.score2,
              remark: this.detailList[i].hash.remark,
              status: '1',
              taskid: this.detailList[i].hash.id,

            };
            f.push(this.spost(this.ts, '/mainservlet', req).then(() => {
              this.$message({
                message: '提交成功！',
                type: 'success',
              });
              this.showCheck = false;
            }));
          }
          Promise.all(f).then(() => {
            this.$message({
              message: '提交成功！',
              type: 'success',
            });
            this.gettestList();
          });
        } else {
          this.$message.error('内容不能为空或不符合规则！');
          return false;
        }
      });
    },
    saveEdit() {
      for (let i = 0; i < this.detailList.length; i += 1) {
        if (Number(this.detailList[i].hash.score1) < 0 || Number(this.detailList[i].hash.score2) < 0) {
          this.$message({
            message: '请检查，得分不能小于0',
            type: 'error',
          });
          return false;
        }
      }
      const e = [];
      for (let i = 0; i < this.detailList.length; i += 1) {
        const req = {
          handle: '04A3682CDCA57EBA0DA6C15FB2ECC84B571521205BF7630E125D30625A61C18F',
          score1: this.detailList[i].hash.score1,
          score2: this.detailList[i].hash.score2,
          remark: this.detailList[i].hash.remark,
          status: '0',
          taskid: this.detailList[i].hash.id,

        };
        e.push(this.spost(this.ts, '/mainservlet', req).then(() => {
          this.showCheck = false;
        }));
      }
      Promise.all(e).then(() => {
        this.$message({
          message: '暂存成功！',
          type: 'success',
        });
        this.gettestList();
      });
    },
    edit(item) {
      if (item.hash.statusname == '已完成') {
        this.ishowsubmit = false;
      } else {
        this.ishowsubmit = true;
      }
      this.showCheck = true;
      const req = {
        handle: '04A3682CDCA57EBA0DA6C15FB2ECC84BECD88FF3EF8A7E3E23BEBB2A1CA3F337BFF0B9210751F692',
        aorgid: item.hash.aorgid,
        time: item.hash.time,
        stype: '1',
      };
      this.spost(this.ts, '/mainservlet', req).then((ts) => {
        this.detailList = ts.d.data.operation1;
      });
    },
    gettestList() {
      const req = {
        handle: '04A3682CDCA57EBA0DA6C15FB2ECC84BECD88FF3EF8A7E3EBDF7AE0978A2036F',
        year: this.year,
        stype: '1',
      };

      this.spost(this.ts, '/mainservlet', req).then((ts) => {
        this.testList = ts.d.data.operation1;
        this.loadingt = false;
      });
    },
  },
};
</script>

<style lang="stylus">
.el-form-item.is-required .el-form-item__label:before
  content: '*'
  color: #f56c6c
.tip1
  width 300px;
  line-height 20px
.f10
  font-size 12px
.el-table .cell
  text-align center
.el-table th>.cell
  text-align center
.el-input--suffix .el-input__inner
  font-size 13px
.el-button
  font-size 13px
.el-select
  width 14%
  margin-right 1%
.select_top
  width 92%
  margin 20px auto
.el-col
  padding: 20px 10px;
</style>
